<!--
 * @Author: Li Zengkun
 * @Date: 2022-06-18 21:42:04
 * @LastEditors: Li Zengkun
 * @LastEditTime: 2022-06-30 23:05:45
 * @Description: Header
-->
<template>
  <div id="header" class="">
    <div class="wrapper">
      <div class="content">
        <!-- headTop -->
        <div id="headTop">
          <a href="#" id="logo">
            <img src="../assets/logo.png" alt="" />
          </a>
          <div id="hcontact" class="fr">
            <i class="fa fa-qq"></i>
            <p>
              <span class="telNum">1743458795</span>
              <br />
              <a href="mailto:1743458795@qq.com">1743458795@qq.com</a>
            </p>
          </div>
        </div>
        <!-- navWrapper -->
        <div id="navWrapper">
          <div class="content">
            <ul class="nav movedx">
              <li class="navitem">
                <a href="#" :class="{ inclick: navItem == 0 }" @click="addClickStyle(0)">
                  <span>首页</span>
                </a>
              </li>
              <li class="navitem">
                <a
                  href="#product"
                  :class="{ inclick: navItem == 1 }"
                  @click="addClickStyle(1)"
                >
                  <span> 产品 </span>
                </a>
              </li>
              <li class="navitem">
                <a
                  href="#hotsell"
                  :class="{ inclick: navItem == 2 }"
                  @click="addClickStyle(2)"
                >
                  <span>热销推荐</span>
                </a>
              </li>
              <li class="navitem">
                <a
                  href="#teammate"
                  :class="{ inclick: navItem == 3 }"
                  @click="addClickStyle(3)"
                >
                  <span>团队精英</span>
                </a>
              </li>
              <li class="navitem">
                <a
                  href="#hotel"
                  :class="{ inclick: navItem == 4 }"
                  @click="addClickStyle(4)"
                >
                  <span>特色酒店</span>
                </a>
              </li>
              <li class="navitem">
                <a
                  style="cursor: auto"
                  :class="{ inclick: navItem == 5 }"
                  id="aboutUs"
                  @click="addClickStyle(5)"
                >
                  <span
                    >关于我们
                    <i class="fa fa-angle-down"></i>
                  </span>
                </a>
                <!-- <a href="#aboutus" id="companyInfo" > 集团简介 </a> -->
                <ul class="subnav">
                  <li>
                    <a href="#companyinfo">集团简介</a>
                  </li>
                </ul>
              </li>
              <li class="navitem">
                <a
                  href="#news"
                  :class="{ inclick: navItem == 6 }"
                  @click="addClickStyle(6)"
                >
                  <span>新闻</span>
                </a>
              </li>
              <li class="navitem">
                <a
                  href="#connectus"
                  :class="{ inclick: navItem == 7 }"
                  @click="addClickStyle(7)"
                >
                  <span>联系我们</span>
                </a>
              </li>
            </ul>
          </div>
        </div>
        <div class="clear"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      navItem: 0,
    };
  },
  components: {},
  mounted() {
    window.addEventListener("scroll", this.header_fiexd);
    this.navItem =
      sessionStorage.getItem("navItem") === null ? 0 : sessionStorage.getItem("navItem");
  },
  // url路径监听
  watch:{
    $route:{
      immediate:true,
      handler(){
        let url = window.location.hash.slice(2)
        let i = 0
        if(url === '') 
          i = 0
        else if(url.includes('product')) 
          i = 1
        else if(url.includes('hotsell')) 
          i = 2
        else if(url.includes('teammate')) 
          i = 3
        else if(url.includes('hotel')) 
          i = 4
        else if(url.includes('companyinfo')) 
          i = 5
        else if(url.includes('news')) 
          i = 6
        else if(url.includes('connectus')) 
          i = 7
        
        
        sessionStorage.setItem('navItem',i)
        this.navItem = i
      },
    },
  },
  methods: {
    header_fiexd() {
      let topScroll = document.documentElement.scrollTop;
      let header = document.getElementById("header");
      let header_height = header.clientHeight;
      if (topScroll >= header_height) {
        header.classList.add("mini");
      } else {
        header.classList.remove("mini");
      }
    },
    
   
    addClickStyle(index) {
      sessionStorage.setItem("navItem", index);
      this.navItem = sessionStorage.getItem("navItem");
    },
  },
};
</script>

<style scoped>
.subnav {
  position: absolute;
  width: 220px;
  background-color: #fff;
  box-shadow: 0 13px 42px 11px rgb(0 0 0 / 5%);
  height: auto;
  z-index: 199;
  top: 97%;
  left: 50%;
  border-top: 2px solid #0072d4;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  transition: all 0.36s ease;
  margin-left: -146px;
  text-align: center;
}
.subnav li {
  transition: all 0.2s ease-in-out;
}
.subnav li a {
  font-weight: 500;
  color: #666;
  padding: 10px 15px;
  line-height: 22px;
  display: block;
  transition: all 0.2s ease-in-out;
  font-size: 13px;
}
.subnav li:hover {
  background: #efefef;
}
.navitem:hover .subnav {
  visibility: visible;
  opacity: 1;
}

#header {
  background-color: #fff;
  width: 100%;
  height: 127px;
  margin-top: 0;
  position: absolute;
  z-index: 999;
}
#header .content {
  height: 100%;
  max-width: 1170px;
  margin: 0 auto;
}
#header #headTop {
  padding: 16px 0;
  height: 40px;
  border-bottom: 1px solid #efefef;
}
#header #headTop a#logo {
  display: block;
  height: 34px;
  float: left;
}
#header #headTop .fr {
  float: right;
}
#header #headTop #hcontact i {
  font-size: 24px;
  float: left;
  line-height: 32px;
  color: #0072d4;
}
#hcontact p {
  margin-left: 30px;
  color: #0072d4;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 22px;
  text-align: left;
}
#hcontact p a {
  color: #3e3e3e;
  font-size: 12px;
  font-family: Arial, Helvetica, sans-serif;
  text-align: right;
  display: block;
}
#header #navWrapper {
  position: relative;
  width: 100%;
  left: 0;
  background: #fff;
  top: 0;
}
#header .nav {
  height: 54px;
}
#header .nav > li {
  float: left;
  /* text-align: center; */
  font-size: 14px;
  height: 100%;
  position: relative;
}
#header .nav > li > a {
  display: block;
  height: 54px;
  line-height: 54px;
  color: #9e9e9e;
  font-weight: 500;
  overflow: hidden;
  margin-right: 60px;
  position: relative;
}
#header .nav > li > a::after {
  content: "";
  width: 100%;
  height: 2px;
  background-color: #0072d4;
  position: absolute;
  bottom: 0;
  display: block;
  transition: all ease-out 0.3s;
  opacity: 0;
}
#header .nav > li a:active::after,
#header .nav > li > a:hover::after {
  opacity: 1;
}
#header .nav > li > a:active,
#header .nav > li > a:hover {
  color: #0072d4;
  display: inline-block;
}
#header .nav > li .inclick {
  color: #0072d4;
  display: inline-block;
}
#header .nav > li .inclick::after {
  content: "";
  width: 100%;
  height: 2px;
  background-color: #0072d4;
  position: absolute;
  bottom: 0;
  display: block;
  transition: all ease-out 0.3s;
  opacity: 1;
}
#header.mini #navWrapper {
  position: fixed;
  margin-top: 0;
  z-index: 999;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  animation: navFixed ease-out 0.3s;
}
@keyframes navFixed {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(0);
  }
}
</style>
